<?php
/**
 * Created by PhpStorm.
 * User: cnpscy
 * Date: 2020/7/7
 * Time: 23:00
 * Note: Admins.php
 */

namespace App\Model\Log;

use App\Model\MonthTable;

class AdminLoginLog extends MonthTable
{
    protected $autoTimeStamp = true;

    public static function createLog($params, $admin, $status = 1, $msg = '', $log_method)
    {
        /**
         * IP 与 浏览器信息
         */
        $ip_agent = get_client_info();
        /**
         * 插入登录日志
         */
        return self::create(
            [
                'request_data' => json_encode($params),
                'admin_id'     => $admin->admin_id,
                'created_ip'   => $ip_agent['ip'] ?? get_ip(),
                'browser_type' => $ip_agent['agent'] ?? $_SERVER['HTTP_USER_AGENT'],
                'created_time' => time(),
                'description'  => $msg ?? "",
                'log_status'   => $status <= 0 ? 0 : 1,
                'log_action'   => '',
                'log_method'   => $log_method,
                'log_duration' => microtime(true) - SYSTEM_START,
            ]
        )->save();
    }
}